1 Libraries

library(tidyverse)

2 Read data

# data needs to be downloaded by hand from https://www.opentable.com/state-of-industry
df_ot <- read_csv("./data/state_of_industry_data.csv") %>%
  pivot_longer( -c(Type, Name), names_to = "Date", values_to = "Value") %>% 
  mutate(Date = as.Date(Date, format="%m/%d"))

countries <- c("Germany", "United States", "United Kingdom", "Global", 
                "Mexico", "Ireland", "Canada", "Australia")

df_ot <- df_ot %>% mutate(
  Group = case_when(Name %in% countries ~ 1,
                    TRUE ~ 2))
updated_on <- df_ot$Date %>% max()

3 Plot by Country

plot <- df_ot %>% filter(Group == 1) %>% 
  ggplot(aes(x = Date, y = Value, color=Value)) + 
  geom_line(show.legend = F) + geom_point() +
  theme(legend.position = "none", 
        axis.title=element_blank()) + 
  scale_y_continuous(breaks = seq(-100, 0, by = 20)) +
  scale_x_date(breaks="1 week", minor_breaks = "day",date_labels = "%b %d") +
  coord_cartesian(ylim=c(-120, 20)) +
  
  
  labs(title = "Effect on Reastaurant Reservations by Country",
       subtitle = paste0("Year-over-year Percentage Change (Updated on : ", updated_on, ")"), 
       caption = "Data source: https://www.opentable.com/state-of-industry") +
  geom_text(aes(label = Value), nudge_y=-10, nudge_x = -1/3, size=3) +
  facet_wrap(~Name, ncol=2)

print(plot)

4 Plot by Cities

plot <- df_ot %>% filter(Group == 2) %>% 
  ggplot(aes(x = Date, y = Value, color=Value)) + 
  geom_line(show.legend = F) + geom_point() +
  theme(legend.position = "none", 
        axis.title=element_blank()) + 
  scale_y_continuous(breaks = seq(-100, 0, by = 20)) +
  scale_x_date(breaks="1 week", minor_breaks = "day",date_labels = "%b %d") +
  coord_cartesian(ylim=c(-120, 20)) +

  
  labs(title = "Effect on Reastaurant Reservations by Cities",
       subtitle = paste0("Year-over-year Percentage Change (Updated on : ", updated_on, ")"), 
       caption = "Data source: https://www.opentable.com/state-of-industry") +
  geom_text(aes(label = Value), nudge_y=-13, nudge_x = -1/3, size=2.3) +
  facet_wrap(~Name, ncol=4) +
  theme(strip.background = element_blank(), strip.placement = "outside")

print(plot)